package es.cea.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LibroEditProcess
 */
@WebServlet("/LibroEditProcess")
public class LibroEditProcess extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		

		PrintWriter writer = response.getWriter();
		String valorNombre = request.getParameter("nombre");
		String valorFecha = request.getParameter("fecha");
		String valorID = request.getParameter("id");
	
		try  
		{  
		Class.forName("com.mysql.jdbc.Driver");  
		Connection conexion = DriverManager.getConnection ("jdbc:mysql://localhost/libreria","root", "root");  
		Statement s = conexion.createStatement();
		
	    s.executeUpdate("update Libros set titulo='" +valorNombre+ "', fecha='"+ valorFecha + "' where id_Libro=" + valorID );  
		conexion.close();
		} catch (Exception e)  
		{  
		   e.printStackTrace();  
		}   
		
		writer.println("libro modificado correctamente: "+ "<br>");
		writer.println("<a href= ./libros> Volver </a>");
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
